// list vuex 模块小仓库

import { reqSearchInfo } from '@/api'

const state = {
  listData: {},
}
const mutations = {
  LISTDATA(state, listdata) {
    state.listData = listdata
  },
}
const actions = {
  async getList({ commit }, params) {
    let result = await reqSearchInfo(params)
    if (result.code == 200) commit('LISTDATA', result.data)
  },
}
const getters = {
  goodsList(){
    // 这样写当state为undifined时，存在错误，要加 || {}
    return state.listData.goodsList || {};
  },
  attrsList(){
    return state.listData.attrsList || {};
  },
  trademarkList(){
    return state.listData.trademarkList || {};
  }
}

export default {
  namespaced: true, //命名空间是防止仓库中出现同名的情况
  state,
  mutations,
  actions,
  getters,
}
